<template>
  <div class="table_container">
    <el-card>
      <!-- 表格区域 -->
      <el-table :data="userlist" style="width: 100%" border>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="registe_time" label="注册日期" width="280"> </el-table-column>
        <el-table-column prop="username" label="用户姓名" width="280"> </el-table-column>
        <el-table-column prop="city" label="注册地址"> </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="offset" :page-sizes="[20, 25, 30, 35, 40]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper" :total="count"> </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { allUserCount } from '../api/index'
import request from '../api/axiosApi'
export default {
  data() {
    return {
      userlist: [],
      count: 0,
      limit: 20,
      offset: 1
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    async initData() {
      try {
        const res = await allUserCount()
        if (res.data.status === 1) {
          this.count = res.data.count
        } else {
          throw new Error('获取数据失败')
        }
        this.getuserinfo()
      } catch (error) {
        console.log('获取数据失败', error)
      }
    },
    // 获取用户列表请求v
    async getuserinfo() {
      const res = await request.get(`/v1/users/list?limit=${this.limit}&offset=${this.offset}`)
      this.userlist = res.data
    },
    handleSizeChange(pangeSize) {
      this.limit = pangeSize
      this.getuserinfo()
    },
    handleCurrentChange(pageNum) {
      this.offset = pageNum
      this.getuserinfo()
    }
  }
}
</script>

<style lang="less"></style>
